package com.shao.controller;


import com.shao.bean.admin;
import com.shao.common.*;
import com.shao.service.admService;
import com.shao.service.teaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: com.song shao
 * @date: 2022/2/27
 * @time: 12:53
 * @version: 1.0
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/adm")
public class admFindStu {

    @Autowired
    private admService as;

    @Autowired
    private teaService tea;

    @Autowired
    private admService adm;

    /**
     * 管理员查询学生的信息
     *
     * @return
     */
    @PostMapping("/findAll")
    public R<List<admStuInfo>> admFindStudentInfo(@RequestBody admin ad) {
        if (as.loginVerify(ad) == null) {
            return R.error("非法操作");
        }
        R<List<admStuInfo>> stuResu = as.admFindStudentInfo();
        return stuResu;
    }

    /**
     * 管理员查询教师的信息
     *
     * @return
     */
    @PostMapping("/findTea")
    public R<List<admStuInfo>> admFindTeacherInfo(@RequestBody admin ad) {
        if (as.loginVerify(ad) == null) {
            return R.error("非法操作");
        }
        List<admStuInfo> admStuInfos = new ArrayList<>();
        List<admTeacherInfo> stuResu = tea.admFindTeacherInfo();
        for (admTeacherInfo admTeacherInfo : stuResu) {
            admStuInfo admStuInfo = new admStuInfo();
            admStuInfo.setStu_username(admTeacherInfo.getTea_username());
            admStuInfo.setStu_state(admTeacherInfo.getTea_state());
            admStuInfo.setClass_name(admTeacherInfo.getClass_name());
            admStuInfo.setStu_nikename(admTeacherInfo.getTea_nikename());
            admStuInfos.add(admStuInfo);
        }
        return R.success(admStuInfos);
    }

    /**
     * 查询管理员的信息
     *
     * @param ad
     * @return
     */
    @PostMapping("/findAdm")
    public R<List<admStuInfo>> admFindAdmInfo(@RequestBody admin ad) {
        if (as.loginVerify(ad) == null) {
            return R.error("非法操作");
        }
        List<admin> result = adm.findAdmInfo();
        List<admStuInfo> ass = new ArrayList<>();
        for (admin admin : result) {
            admStuInfo admStuInfo = new admStuInfo();
            admStuInfo.setStu_nikename(admin.getAdm_username());
            admStuInfo.setStu_state(0);
            admStuInfo.setStu_username(admin.getAdm_username());
            admStuInfo.setClass_name("管理员无处不在");
            ass.add(admStuInfo);
        }
        return R.success(ass);
    }

    /**
     * 逻辑删除账号的（其实就是封禁）
     * 暂时未完成
     *
     * @param stu_username
     */
    @PostMapping("/del")
    public R deleteStu(@RequestBody kes stu_username) {
        System.out.println(stu_username);
        return as.deleteStu(stu_username);
    }

    /**
     * 添加教师
     *
     * @param stu_username
     * @return
     */
    @PostMapping("/addTea")
    public R addTeacher(@RequestBody addTeacherVo adm) {
        boolean resu = tea.addTeacher(adm);
        return resu ? R.success(1) : R.error("班级不存在或密码和账号错错误（账号11位 密码7位以上）");
    }
}
